$(function () {
	
	
    //动态树形菜单数据
    var treeData = [{
    	  text : "网管系统",
          children : [{
        	  	  state: "closed",
                  text : "系统管理",
                  children : [{
                          text : "系统拓扑",
                          attributes : {
                              url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/sys_manage/systemTopology.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
                          }
                      }, {
                          text : "前置机状态",
                          attributes : {
                              url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/sys_manage/frontEndProcessorState.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'

                          }
                      }, {
                          text : "服务器状态",
                          attributes : {
                              url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/sys_manage/serverState.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'

                          }
                      }
                  ]
              },{
            	  state: "closed",
                  text : "配置管理",
                  children : [{
                          text : "配置前置机",
                          attributes : {
                              url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/conf manage/frontEndProcessorConfiguration.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
                          }
                      }, {
                          text : "Train_Info数据维护",
                          attributes : {
                              url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/conf manage/train_infoDataMaintenance.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
                          }
                      }, {
                          text : "Bs_Info数据维护",
                          attributes : {
                              url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/conf manage/bs_infoDataMaintenance.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
                          }
                      }, {
                          text : "应答器数据维护",
                          attributes : {
                              url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/conf manage/balise_infoDataMaintenance.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
                          }
                      }, {
                          text : "GPRS_Info数据维护",
                          attributes : {
                              url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/conf manage/gprs_infoDataMaintenance.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
                          }
                      }
                  ]
              },{
            	  state: "closed",
                  text : "系统性能",
                  children : [{
                          text : "前置机实时性能",
                          attributes : {
                              url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/perform_manage/frontEndProcessorRealtimePerformance.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
                          }
                      }, {
                          text : "前置机性能",
                          attributes : {
                              url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/perform_manage/frontEndProcessorPerformance.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
                          }
                      }, {
                          text : "服务器实时性能",
                          attributes : {
                              url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/perform_manage/serverRealtimePerformance.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
                          }
                      }, {
                          text : "服务器性能",
                          attributes : {
                              url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/perform_manage/serverPerformance.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
                          }
                      }
                  ]
              },{
            	  state: "closed",
                  text : "告警管理",
                  children : [{
                          text : "告警记录",
                          attributes : {
                              url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/alarm_manage/realtimeAlarmInformation.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
                          }
                      },{
                          text : "历史告警",
                          attributes : {
                              url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/alarm_manage/alarmHistoryQuery.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
                          }
                      },
                  ]
              },{
            	  state: "closed",
                  text : "日志管理",
                  children : [{
                          text : "操作记录",
                          attributes : {
                              url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/log_manage/sysOperationRecord.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
                          }
                      }
                  ]
              }
          ]
      }];
    
    
    var treeData2 = [{
  	  text : "网管系统",
        children : [{
      	  	  state: "closed",
                text : "系统管理",
                children : [{
                        text : "系统拓扑",
                        attributes : {
                            url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/sys_manage/systemTopology.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
                        }
                    }, {
                        text : "前置机状态",
                        attributes : {
                            url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/sys_manage/frontEndProcessorState.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'

                        }
                    }, {
                        text : "服务器状态",
                        attributes : {
                            url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/sys_manage/serverState.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'

                        }
                    }
                ]
            },{
          	  state: "closed",
                text : "系统性能",
                children : [{
                        text : "前置机实时性能",
                        attributes : {
                            url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/perform_manage/frontEndProcessorRealtimePerformance.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
                        }
                    }, {
                        text : "前置机性能",
                        attributes : {
                            url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/perform_manage/frontEndProcessorPerformance.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
                        }
                    }, {
                        text : "服务器实时性能",
                        attributes : {
                            url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/perform_manage/serverRealtimePerformance.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
                        }
                    }, {
                        text : "服务器性能",
                        attributes : {
                            url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/perform_manage/serverPerformance.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
                        }
                    }
                ]
            },{
          	  state: "closed",
                text : "告警管理",
                children : [{
                        text : "实时告警信息",
                        attributes : {
                            url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/alarm_manage/realtimeAlarmInformation.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
                        }
                    },{
                        text : "历史告警信息",
                        attributes : {
                            url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/alarm_manage/alarmHistoryQuery.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
                        }
                    }/*,{
                        text : "GPRS数据中断统计",
                        attributes : {
                            url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/alarm_manage/gprsAlarmCount.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
                        }
                    }*/
                ]
            },{
          	  state: "closed",
                text : "日志管理",
                children : [{
                        text : "操作记录",
                        attributes : {
                            url : '<iframe width="100%" height="100%" frameborder="0"  src="page/networkManagement/log_manage/sysOperationRecord.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
                        }
                    }
                ]
            }
        ]
    }];
    
    
    //实例化树形菜单
    $("#tree").tree({
    	
        data : treeData,
        lines : true,
        onClick : function (node) {
            if (node.attributes) {
                Open(node.text, node.attributes.url);
            }
        }
    });
    $("#tree2").tree({
    	
        data : treeData2,
        lines : true,
        onClick : function (node) {
            if (node.attributes) {
                Open(node.text, node.attributes.url);
            }
        }
    });
    //在右边center区域打开菜单，新增tab
    function Open(text, url) {
        if ($("#tabs").tabs('exists', text)) {
            $('#tabs').tabs('select', text);
        } else {
            $('#tabs').tabs('add', {
                title : text,
                closable : true,
                content : url
            });
        }
    }
    
    //绑定tabs的右键菜单
    $("#tabs").tabs({
        onContextMenu : function (e, title) {
            e.preventDefault();
            $('#tabsMenu').menu('show', {
                left : e.pageX,
                top : e.pageY
            }).data("tabTitle", title);
        }
    });
    
    //实例化menu的onClick事件
    $("#tabsMenu").menu({
        onClick : function (item) {
            CloseTab(this, item.name);
        }
    });
    
    //几个关闭事件的实现
    function CloseTab(menu, type) {
        var curTabTitle = $(menu).data("tabTitle");
        var tabs = $("#tabs");
        
        if (type === "close") {
            tabs.tabs("close", curTabTitle);
            return;
        }
        
        var allTabs = tabs.tabs("tabs");
        var closeTabsTitle = [];
        
        $.each(allTabs, function () {
            var opt = $(this).panel("options");
            if (opt.closable && opt.title != curTabTitle && type === "Other") {
                closeTabsTitle.push(opt.title);
            } else if (opt.closable && type === "All") {
                closeTabsTitle.push(opt.title);
            }
        });
        
        for (var i = 0; i < closeTabsTitle.length; i++) {
            tabs.tabs("close", closeTabsTitle[i]);
        }
    }
});